/*
 * Copyright (C) 2011 Dirk Weißenborn, dirk.weissenborn@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.weissenborn.colabtex.client.service;

import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * The Interface EtherpadService which is used to communicate group and pad operations with the server
 */
@RemoteServiceRelativePath("EtherpadService")
public interface EtherpadService extends RemoteService {
	
	/**
	 * Creates a group.
	 *
	 * @param groupName the groups name
	 * @param members the members, where an entry consists of a users id and his role (admin, editor, read-only)
	 * @return whether group was created
	 */
	public Boolean createGroup(String groupName, Map<String, String> members);
	
	/**
	 * Delete group.
	 *
	 * @param groupName the group name
	 * @return whether group was deleted
	 */
	public Boolean deleteGroup(String groupName);
	
	/**
	 * Creates a group pad.
	 *
	 * @param groupName the group name
	 * @param padName the pad name
	 * @return whether pad was created
	 */
	public Boolean createGroupPad(String groupName, String padName);
	
	/**
	 * Delete a group pad.
	 *
	 * @param groupName the group name
	 * @param padName the pad name
	 */
	public void deleteGroupPad(String groupName, String padName);
	
	/**
	 * List pads.
	 *
	 * @param permission the permission
	 * @param groupName the group name
	 * @return a map of pad ids to urls of these pad
	 */
	public Map<String,String> listPads(String permission, String groupName);
	
	/**
	 * Lists groups of an user 
	 *
	 * @param userId the users id
	 * @return a map of names of group to the users permission for this group
	 */
	public Map<String,String> listGroups(String userId);
	
	/**
	 * Adds the permission.
	 *
	 * @param groupName the group name
	 * @param memberId the member id
	 * @param role the role
	 * @return whether permission was added
	 */
	public Boolean addPermission(String groupName, String memberId, String role);
	
	/**
	 * Removes the permission.
	 *
	 * @param groupName the group name
	 * @param memberName the member name
	 * @param yourself the yourself
	 * @return whether permission was removed
	 */
	public Boolean removePermission(String groupName, String memberName, Boolean yourself);
	
	/**
	 * List members.
	 *
	 * @param groupName the group name
	 * @return a map of member ids to their permissions in this group
	 */
	public Map<String,String> listMembers(String groupName);
	
	/**
	 * The Class Util.
	 */	
	public static class Util {
		
		/** The instance. */
		private static EtherpadServiceAsync instance;
		
		/**
		 * Gets the single instance of Util.
		 *
		 * @return single instance of Util
		 */
		public static EtherpadServiceAsync getInstance(){
			if (instance == null) {
				instance = GWT.create(EtherpadService.class);
			}
			return instance;
		}
	}
}
